﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ElementumForever.Interfaces;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ElementumForever.Factory;
using ThirdPartyNinjas.XnaUtility;
using ElementumForever.Utility;
using Microsoft.Xna.Framework.Input;

namespace ElementumForever.Decorators
{
    class SelectDecorator : BaseUIDecorator
    {
        XmlTexture xmlTexture;
        string vertexId = "selectVertex";
        string centerId = "selectCenter";


        public SelectDecorator(BaseEntity master)
            : base(master)
        {
            //masterColor = master.Color;
        }

        public override void OnCreat()
        {
            base.OnCreat();
            IsSelect = false;
            xmlTexture = ContentFactory.LoadXmlTexture("images/editerImages");
        }

        protected override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {           
            if (IsSelect)
                DrawSelectedComponent(spriteBatch);
        }

        public override void OnMouseClick(MouseState state)
        {
            base.OnMouseClick(state);
            Vector2 v = new Vector2(state.X,state.Y);
            Console.WriteLine("LocalPos:" + _component.GetLocalPosition(v));
        }

        protected void DrawSelectedComponent(SpriteBatch spriteBatch)
        {
            DrawXmlTexture(xmlTexture, vertexId, topLeft, 0, spriteBatch);
            DrawXmlTexture(xmlTexture, vertexId, downLeft, 0, spriteBatch);
            DrawXmlTexture(xmlTexture, vertexId, downRight, 0, spriteBatch);
            DrawXmlTexture(xmlTexture, vertexId, topRight, 0, spriteBatch);
            DrawXmlTexture(xmlTexture, centerId, center, 0, spriteBatch);
        }

        protected void DrawXmlTexture(XmlTexture xmlTexture, string id, Vector2 pos, float rotation, SpriteBatch spriteBatch)
        {
            TextureRegion region = xmlTexture.GetRegion(id);
            Rectangle bound = region.Bounds;
            Vector2 scale = new Vector2(1f / ScaleX, 1f / ScaleY);
            spriteBatch.Draw(xmlTexture.Texture2D, pos, bound, Color.White, rotation, region.OriginCenter, scale, SpriteEffects.None, LayerDepth);
        }

    }
}
